package jnpf.service.impl;

import jnpf.entity.Whu_comprehensiveabilityEntity;
import jnpf.mapper.Whu_comprehensiveabilityMapper;
import jnpf.service.Whu_comprehensiveabilityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.util.RandomUtil;


import jnpf.model.whu_comprehensiveability.Whu_comprehensiveabilityPagination;
import java.util.stream.Collectors;





import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.text.SimpleDateFormat;
import jnpf.util.*;
import java.util.*;

/**
 *
 * whu_comprehensiveability
 * 版本： V3.2.0
 * 版权： 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * 作者： JNPF开发平台组
 * 日期： 2025-06-10
 */
@Service

public class Whu_comprehensiveabilityServiceImpl extends ServiceImpl<Whu_comprehensiveabilityMapper, Whu_comprehensiveabilityEntity> implements Whu_comprehensiveabilityService {

    @Autowired
    private UserProvider userProvider;






    @Override
    public List<Whu_comprehensiveabilityEntity> getList(Whu_comprehensiveabilityPagination whu_comprehensiveabilityPagination){
        String userId = userProvider.get().getUserId();
        List<String> AllIdList = new ArrayList();
        int total = 0;
        QueryWrapper<Whu_comprehensiveabilityEntity> whu_comprehensiveabilityQueryWrapper = new QueryWrapper<>();
        // 只允许查自己的数据
        whu_comprehensiveabilityQueryWrapper.lambda().eq(Whu_comprehensiveabilityEntity::getUserid, userId);

        if(AllIdList.size() > 0){
            whu_comprehensiveabilityQueryWrapper.lambda().in(Whu_comprehensiveabilityEntity::getId, AllIdList);
        }
        //排序
        if(StringUtil.isEmpty(whu_comprehensiveabilityPagination.getSidx())){
            whu_comprehensiveabilityQueryWrapper.lambda().orderByDesc(Whu_comprehensiveabilityEntity::getId);
        }else{
            whu_comprehensiveabilityQueryWrapper = "asc".equals(whu_comprehensiveabilityPagination.getSort().toLowerCase())
                ? whu_comprehensiveabilityQueryWrapper.orderByAsc(whu_comprehensiveabilityPagination.getSidx())
                : whu_comprehensiveabilityQueryWrapper.orderByDesc(whu_comprehensiveabilityPagination.getSidx());
        }
        if((total > 0 && AllIdList.size() > 0) || total == 0){
            Page<Whu_comprehensiveabilityEntity> page = new Page<>(whu_comprehensiveabilityPagination.getCurrentPage(), whu_comprehensiveabilityPagination.getPageSize());
            IPage<Whu_comprehensiveabilityEntity> userIPage = this.page(page, whu_comprehensiveabilityQueryWrapper);
            return whu_comprehensiveabilityPagination.setData(userIPage.getRecords(), userIPage.getTotal());
        }else{
            List<Whu_comprehensiveabilityEntity> list = new ArrayList();
            return whu_comprehensiveabilityPagination.setData(list, list.size());
        }
    }
    @Override
    public List<Whu_comprehensiveabilityEntity> getTypeList(Whu_comprehensiveabilityPagination whu_comprehensiveabilityPagination, String dataType){
        String userId = userProvider.get().getUserId();
        List<String> AllIdList = new ArrayList();
        int total = 0;
        QueryWrapper<Whu_comprehensiveabilityEntity> whu_comprehensiveabilityQueryWrapper = new QueryWrapper<>();
        // 只允许查自己的数据
        whu_comprehensiveabilityQueryWrapper.lambda().eq(Whu_comprehensiveabilityEntity::getUserid, userId);

        if(AllIdList.size() > 0){
            whu_comprehensiveabilityQueryWrapper.lambda().in(Whu_comprehensiveabilityEntity::getId, AllIdList);
        }
        //排序
        if(StringUtil.isEmpty(whu_comprehensiveabilityPagination.getSidx())){
            whu_comprehensiveabilityQueryWrapper.lambda().orderByDesc(Whu_comprehensiveabilityEntity::getId);
        }else{
            whu_comprehensiveabilityQueryWrapper = "asc".equals(whu_comprehensiveabilityPagination.getSort().toLowerCase())
                ? whu_comprehensiveabilityQueryWrapper.orderByAsc(whu_comprehensiveabilityPagination.getSidx())
                : whu_comprehensiveabilityQueryWrapper.orderByDesc(whu_comprehensiveabilityPagination.getSidx());
        }
        if("0".equals(dataType)){
            if((total > 0 && AllIdList.size() > 0) || total == 0){
                Page<Whu_comprehensiveabilityEntity> page = new Page<>(whu_comprehensiveabilityPagination.getCurrentPage(), whu_comprehensiveabilityPagination.getPageSize());
                IPage<Whu_comprehensiveabilityEntity> userIPage = this.page(page, whu_comprehensiveabilityQueryWrapper);
                return whu_comprehensiveabilityPagination.setData(userIPage.getRecords(), userIPage.getTotal());
            }else{
                List<Whu_comprehensiveabilityEntity> list = new ArrayList();
                return whu_comprehensiveabilityPagination.setData(list, list.size());
            }
        }else{
            return this.list(whu_comprehensiveabilityQueryWrapper);
        }
    }

    @Override
    public Whu_comprehensiveabilityEntity getInfo(String id){
        QueryWrapper<Whu_comprehensiveabilityEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(Whu_comprehensiveabilityEntity::getId,id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(Whu_comprehensiveabilityEntity entity){
        String userId = userProvider.get().getUserId();
        entity.setUserid(userId);
        this.save(entity);
    }

    @Override
    public boolean update(String id, Whu_comprehensiveabilityEntity entity){
        entity.setId(id);
        return this.updateById(entity);
    }
    @Override
    public void delete(Whu_comprehensiveabilityEntity entity){
        if(entity!=null){
            this.removeById(entity.getId());
        }
    }
    //子表方法

    //列表子表数据方法

}
